<{include file="common/header" title="商品管理" /}>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>修改内容</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="<{:url('goodEdit',input('get.'))}>" enctype="multipart/form-data">
            <input type="hidden" name="goods_id" value="<{$goods_id}>">
            <div class="form-group">
                <div class="label">
                    <label>商品名：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="<{$goods_name}>" name="goods_name"
                           data-validate="required:请输入商品名"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>原价：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="<{$price}>" name="price"
                           data-validate="required:请输入价格"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>VIP价：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="<{$vip}>" name="vip" data-validate="required:请输入价格"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>商品库存：</label>
                </div>
                <div class="field">
                    <input type="number" class="input w50" value="<{$spec_qty}>" name="spec_qty"
                           data-validate="required:请输入库存"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>图片：</label>
                </div>
                <div class="field">
                    <input type="text" readonly id="url1" data-image="/images/<{$default_image}>"  class="input tips" style="width:25%; float:left;" value="<{$default_image}>" data-toggle="hover" data-place="right" />
                    <input type="button"  class="button bg-blue margin-left" value="+ 浏览上传" >
                    <input type="file" name="default_image" onchange="url1.value=this.value" style="position:relative; z-index:1000px; filter:alpha(opacity=0);-moz-opacity:0; opacity:0; left:-155px;" />
                </div>
            </div>
            <div class="form-group">
                <div class="label"><label>轮播图：</label></div>
                <div class="field">
                    <span id="img-list-box" style="margin-left: 25px;">
                        <{if isset($images) && !empty($images)}>
                        <{foreach $images as $v}>
                        <div style="position: relative;margin-right: 20px;margin-bottom: 15px;width: 132px;display: inline-block;border: 1px solid #CCC;background:#EEE;"><span style="display: block;width: 120px;height: 80px;border: 1px solid #F2F1F0;margin: 5px;overflow: hidden;">
                      <img src="/images/<{$v}>" style="width: 100%;height: 100%;"/></span>
                        <input type="hidden" name="old_imgs[]" value="<{$v}>"/><a onclick="delImg(this);" style="z-index: 10;display: block;top: -8px;cursor:pointer;right: -8px;position:absolute;width: 20px;height: 20px;background: #CCC;border-radius:100%;text-align:center;line-height: 20px;border: 1px solid #C1C1C1;color: #555;">X</a></div>
                        <{/foreach}>
                        <{/if}>
                    </span>
                    <span style="display:inline-block;height: 30px;position: relative;top:0px;left:0px;">
                    <a  class="button bg-blue margin-left">+上传轮播图</a>
                    <input type="file" name="img_src" style="width: 100px;border: 1px solid red;position: absolute;top:0px;left: 0px;height: 30px;opacity: 0;" id="up-img-file" onchange="upimg(this)">
                   </span>
                </div>
            </div>
            <div class="form-group" id="typeTitle">
                <div class="label">
                    <label>分类标题：</label>
                </div>
                <div class="field">
                    <select name="cate_id" class="input w50">
                        <option value="">请选择分类</option>
                        <{foreach $cateList as $v}>
                        <optgroup label="<{$v['cate_name']}>">
                            <{if is_array($v['next'])}>
                            <{foreach $v['next'] as $vv}>
                            <option value="<{$vv['cate_id']}>" disabled >&nbsp;&nbsp;&nbsp;&nbsp;|-<{$vv['cate_name']}></option>
                            <{if is_array($vv['next'])}>
                            <{foreach $vv['next'] as $vvv}>
                            <option value="<{$vvv['cate_id']}>" <{if $vvv['cate_id']==$cate_id}>selected<{/if}> >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--<{$vvv['cate_name']}></option>
                            <{/foreach}>
                            <{/if}>
                            <{/foreach}>
                            <{/if}>
                        </optgroup>
                        <{/foreach}>
                    </select>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>品牌：</label>
                </div>
                <div class="field">
                    <select name="brand" class="input w50">
                        <option value="">请选择品牌</option>
                        <{foreach name='brandList' item='vo'}>
                        <option <{if $vo['brand_id'] == $brand}>selected<{/if}> value="<{$vo['brand_id']}>"><{$vo['brand_name']}></option>
                        <{/foreach}>
                    </select>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>其他属性：</label>
                </div>
                <div class="field" style="padding-top:8px;">
                    推荐 <input name="recommended" <{if $recommended== 1}>checked<{/if}> value="1" type="radio"/>
                    不推 <input name="recommended" <{if $recommended== 0}>checked<{/if}>  value="0" type="radio"/>&nbsp;&nbsp;&nbsp;
                    热门 <input name="recom" <{if $recom== 1}>checked<{/if}> value="1" type="radio"/>
                    冷门 <input name="recom" <{if $recom== 0}>checked<{/if}> value="0" type="radio"/>&nbsp;&nbsp;&nbsp;
                    上架 <input name="if_show" <{if $if_show== 1}>checked<{/if}> value="1" type="radio"/>
                    下架 <input name="if_show"<{if $if_show== 0}>checked<{/if}> value="0" type="radio"/>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>详情：</label>
                </div>
                <div class="field">
                    <textarea name="description" class="input" style="height:250px; border:1px solid #ddd;"><{$description}></textarea>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit"  name="btn" value="1"> 提交</button>
                    <!--<button class="button bg-main icon-check-square-o" type="submit" name="btn" value="0"> 返回</button>-->
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    function upimg(obj) {
        if (obj.value == "") {
            return;
        }
        var formdata = new FormData();
        //<input type="file" name="img" value="" />
        formdata.append("img", $(obj)[0].files[0]);//获取文件法二
        $.ajax({
            type: 'post',
            url: "<{:url('upload/ajaxUpload')}>", //接口
            data: formdata,
            cache: false,
            processData: false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
            contentType: false, // 不设置Content-type请求头
            success: function (response) {
                console.log(response);
                var html = '<div style="position: relative;margin-right: 20px;margin-bottom: 15px;width: 132px;display: inline-block;border: 1px solid #CCC;background:#EEE;">'
                    + '<span style="display: block;width: 120px;height: 80px;border: 1px solid #F2F1F0;margin: 5px;overflow: hidden;">'
                    + '<img src="/images/' + response + '" style="width: 100%;height: 100%;" />'
                    + '</span>'
                    + '<input type="hidden" name="new_imgs[]" value="' + response + '" />'
                    + '<a onclick="delImg(this);" style="z-index: 10;display: block;top: -8px;cursor:pointer;right: -8px;position:absolute;width: 20px;height: 20px;background: #CCC;border-radius:100%;text-align:center;line-height: 20px;border: 1px solid #C1C1C1;color: #555;">X</a>'
                    + '</div>';
                $('#img-list-box').append(html);
            },
            error: function () {
            }
        });
    }

    function delImg(obj) {
        $(obj).parent('div').remove();
    }
</script>
</html>